import 'package:boss/color_constant.dart';
import 'package:boss/models/takeout_order_list_data.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/custom_divier.dart';
import 'package:boss/ui/widget/shadow_radius_card.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

import 'commodity_row.dart';

class TakeoutCommodityPanel extends StatelessWidget {
  final TakeoutOrderItem data;

  const TakeoutCommodityPanel({Key key, this.data}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ShadowRadiusCard(
      margin: EdgeInsets.only(top: 30.w),
      child: Column(
        children: <Widget>[
          Container(
            height: 80.w,
            padding: EdgeInsets.symmetric(horizontal: 20.w),
            alignment: Alignment.centerLeft,
            child: Text(
              '商品信息',
              style: TextStyleConstant().normal_3_28,
            ),
          ),
          CustomDivider(),
          for (final item in data.takeOutOrderDetails)
            CommodityRow(
              data: item,
            ),
          _TitleValue(
            title: '包装费',
            price: data.packFee,
          ),
          _TitleValue(
            title: '配送费',
            price: data.deliverFee,
          ),
          _TitleValue(
            title: '优惠合计',
            price: data.couponFee,
          ),
          _TitleValue(
            title: '配送员小费',
            price: data.tip,
          ),
          _TitleValue(
            title: '商品金额',
            price: data.orderAmount,
          ),
          _TotalAmountRow(data.totalAmount),
        ],
      ),
    );
  }
}

class _TitleValue extends StatelessWidget {
  final String title;
  final int price;

  const _TitleValue({
    Key key,
    @required this.title,
    @required this.price,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    if (price == 0) {
      return SizedBox();
    }
    return DefaultTextStyle(
      style: TextStyleConstant().normal_1_28,
      child: Container(
        height: 90.w,
        padding: EdgeInsets.symmetric(horizontal: 30.w),
        decoration: BoxDecoration(border: Border(bottom: BorderSide(color: ColorConstant.e6e6, width: 1.px))),
        alignment: Alignment.centerLeft,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Text(title),
            TakeOutPriceText(price: price),
          ],
        ),
      ),
    );
  }
}

class _TotalAmountRow extends StatelessWidget {
  final int price;

  const _TotalAmountRow(this.price);

  @override
  Widget build(BuildContext context) {
    final yuan = price ~/ 100;
    final fen = price % 100;
    final color = ColorConstant.fbd43;

    return Container(
        height: 90.w,
        padding: EdgeInsets.symmetric(horizontal: 30.w),
        alignment: Alignment.centerRight,
        child: RichText(
          textAlign: TextAlign.end,
          text: TextSpan(text: '实收金额：', style: TextStyleConstant().normal_1_24, children: [
            TextSpan(
              text: '¥',
              style: TextStyle(
                fontSize: 20.sp,
                color: color,
                fontWeight: FontWeight.bold,
              ),
            ),
            TextSpan(
              text: '$yuan',
              style: TextStyle(
                fontSize: 36.sp,
                color: color,
                fontWeight: FontWeight.bold,
                fontFamily: 'DINAlternate-Bold',
              ),
            ),
            TextSpan(
              text: '.$fen',
              style: TextStyle(
                fontSize: 20.sp,
                color: color,
                fontWeight: FontWeight.bold,
                fontFamily: 'DINAlternate-Bold',
              ),
            ),
          ]),
        ));
  }
}
